#include "adcdeal.h"
#include "tcpdata.h"
#include "string.h"
#include "timer.h"
#include "gsm.h"
#include "IAP.h"
#include "math.h"
u16 Collect_10A[100];
u8 Collect_10ANum=0;
u16 Collect_20A[100];
u8 Collect_20ANum=0;
u16 TmpNow[2];
u16 Device_value1;
u16 Device_value2;
u16 AD_Date1=0;
u16 AD_Date2=0;
u8 DeviceOne=0;
u8 DeviceTwo=0;

float SquareRootFloat(float number)
{
    long i;
    float x, y;
    const float f = 1.5F;
    x = number * 0.5F;
    y = number;
    i = *(long *)&y;
    i = 0x5f3759df - (i >> 1); //???
                               //i  = 0x5f375a86 - ( i >> 1 );  //Lomont
    y = *(float *)&i;
    y = y * (f - (x * y * y));
    y = y * (f - (x * y * y));
    return number * y;
}
u16 calc(unsigned short *pData, int nNum)
{
    long int fSum = 0, i;
    for (i = 0; i < nNum; i++)
    {
        fSum += pData[i] * pData[i]; 
    }
    return SquareRootFloat(fSum * 10 / nNum); 
}
void Tm4AdDeal_Pro()
{
        Collect_10A[Collect_10ANum++] = TmpNow[0];
        Collect_20A[Collect_20ANum++] = TmpNow[1];
        if (Collect_10ANum > 99)
        {
            AD_Date1 = calc(Collect_10A, 100);
            Collect_10ANum = 0;
            memset(Collect_10A, 0, 100);
        }
        if (Collect_20ANum > 99)
        {
            AD_Date2 = calc(Collect_20A, 100);
            Collect_20ANum = 0;
            memset(Collect_20A, 0, 100);
        }
        if (AD_Date1 > Device_value1)
        {
            DeviceOne = 1;
        }
        else
        {
            DeviceOne = 0;
        }
        if (AD_Date2 > Device_value2)
        {
            DeviceTwo = 1;
        }
        else
        {
            DeviceTwo = 0;
        }
}


